package com.explorati.LeetCode344.reversestring;

/**
 * 344. Reverse String 解法一：指针对撞
 * 
 * Write a function that reverses a string. The input string is given as an
 * array of characters char[].
 * 
 * Do not allocate extra space for another array, you must do this by modifying
 * the input array in-place with O(1) extra memory.
 * 
 * @author explorati
 *
 */
public class Solution {
	public void reverseString(char[] s) {
		int i = 0, j = s.length - 1;
		while (i < j) {
			swap(s, i, j);
			i++;
			j--;
		}
	}

	public static void swap(char[] s, int i, int j) {
		char temp = s[i];
		s[i] = s[j];
		s[j] = temp;
	}
}
